<?php
namespace app\ctrl;
use \app\model\mesModel;
/**
* index
*/
class indexCtrl extends \core\main
{
	public function index()
	{
		//$model = new \app\model\userModel();
		/*$ret = $model->lists();
		dump($ret);*/
		/*$res = $model->getOne(4);
		dump($res);*/
		/*$data = array(
			'username' => 'test',
			'password' => 'test',
			'age' => 30
		);
		$res = $model->setOne(4, $data);*/
		/*$res = $model->del(4);
		dump($res);*/

		/*$data = array(
			'title' => '视图文件',
			'content' => 'hello world'
		);
		$this->assign('data', $data);
		$this->display('index.html');*/

		//所有留言
		$model = new mesModel();
		$data = $model->all();
		$this->assign('data', $data);
		$this->display('index.html');
	}
	//添加留言
	public function add()
	{
		$this->display('add.html');
	}
	//保存留言
	public function save()
	{
		$data['title'] = post('title');
		$data['content'] = post('content');
		$data['createtime'] = time();
		$model = new mesModel();
		$res = $model->addOne($data);
		if ($res) {
			jump('/myframework/');
		} else {
			p('error');
		}
	}
	//删除留言
	public function del()
	{
		$id = get('id', 0, 'int');
		if ($id) {
			$model = new mesModel();
			$res = $model->delOne($id);
			if ($res) {
				jump('/myframework/');
			} else {
				p('error');
			}
		} else {
			exit('参数错误');
		}
	}

	public function test()
	{
		$data = array(
			'title' => 'test',
			'content' => 'hello world'
		);
		$this->assign('data', $data);
		$this->display('test.html');
	}
}